package com.googlecode.kipler.satisfiability.completion.rule.individual.uniformnotation;

import com.googlecode.kipler.syntax.LTLBinaryOperator;
import com.googlecode.kipler.syntax.LTLUnaryOperator;
import com.googlecode.kipler.syntax.concept.BooleanConcept;
import com.googlecode.kipler.syntax.concept.Concept;
import com.googlecode.kipler.syntax.concept.LTLBinaryConcept;
import com.googlecode.kipler.syntax.concept.LTLUnaryConcept;


public class BeforeAlphaConcept implements AlphaConcept {

	private LTLBinaryConcept binCon;

	private Concept alpha1, alpha2;

	private boolean valid;

	public BeforeAlphaConcept() {
		super();
	}

	public BeforeAlphaConcept(Concept concept) {
		setAlpha(concept);
	}

	@Override
	public void setAlpha(Concept concept) {
		valid = false;
		if (concept instanceof LTLBinaryConcept) {
			binCon = (LTLBinaryConcept) concept;
			if (binCon.getConstructor() == LTLBinaryOperator.BEFORE) {
				alpha1 = binCon.getRhs().copy().toggleNegated();
				alpha2 = new BooleanConcept(BooleanConcept.Constructor.UNION,
						binCon.getLhs(), new LTLUnaryConcept(
								LTLUnaryOperator.NEXT, concept));
				valid = true;
			}
		}
	}

	@Override
	public Concept getAlpha1() {
		return alpha1;
	}

	@Override
	public Concept getAlpha2() {
		return alpha2;
	}

	public boolean isValid() {
		return valid;
	}

}
